package org.maxgroundstation.groundstation.view.overlay;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * A utility class for overlays.
 * @author Scott Davis
 * 
 * Copyright (C) 2010  Scott Davis
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
public final class OverlayUtil {

    // List of overlays.
    private static List<Overlay> overlayList;
    
    // Private default constructor for utility class.
    private OverlayUtil() {};
    
    /**
     * Adds an overlay graphic.
     * @param overlay the overlay graphic.
     */
    public static void addOverlay(Overlay overlay) {
        if (overlayList == null) overlayList = new ArrayList<Overlay>();
        
        if (!overlayList.contains(overlay)) overlayList.add(overlay);
    }
    
    /**
     * Gets all overlay graphics.
     * @return list of overlay graphics.
     */
    public static List<Overlay> getOverlays() {
        if (overlayList == null) overlayList = new ArrayList<Overlay>();
        
        return new ArrayList<Overlay>(overlayList);
    }
    
    /**
     * Gets an overlay with a given name.
     * @param overlayName the overlay name.
     * @return overlay or null if none found.
     */
    public static Overlay getOverlay(String overlayName) {
        if (overlayList == null) overlayList = new ArrayList<Overlay>();
        
        Overlay result = null;
        
        Iterator<Overlay> i = overlayList.iterator();
        while (i.hasNext()) {
            Overlay overlay = i.next();
            if (overlay.getName().equalsIgnoreCase(overlayName)) {
                result = overlay;
            }
        }
        
        return result;
    }
}